home *** CD-ROM | disk | FTP | other *** search
/ The World of Computer Software / The World of Computer Software.iso / srcuc.zip / UX.H < prev    next >
C/C++ Source or Header  |  1992-01-20  |  23KB  |  1,069 lines

  1. /* -*-C-*-
  2.  
  3. $Header: /scheme/src/microcode/RCS/ux.h,v 1.30 1992/01/20 18:06:15 jinx Exp $
  4.  
  5. Copyright (c) 1988-1992 Massachusetts Institute of Technology
  6.  
  7. This material was developed by the Scheme project at the Massachusetts
  8. Institute of Technology, Department of Electrical Engineering and
  9. Computer Science.  Permission to copy this software, to redistribute
  10. it, and to use it for any purpose is granted, subject to the following
  11. restrictions and understandings.
  12.  
  13. 1. Any copy made of this software must include this copyright notice
  14. in full.
  15.  
  16. 2. Users of this software agree to make their best efforts (a) to
  17. return to the MIT Scheme project any improvements or extensions that
  18. they make, so that these may be included in future releases; and (b)
  19. to inform MIT of noteworthy uses of this software.
  20.  
  21. 3. All materials developed as a consequence of the use of this
  22. software shall duly acknowledge such use, in accordance with the usual
  23. standards of acknowledging credit in academic research.
  24.  
  25. 4. MIT has made no warrantee or representation that the operation of
  26. this software will be error-free, and MIT is under no obligation to
  27. provide any services, by way of maintenance, update, or otherwise.
  28.  
  29. 5. In conjunction with products arising from the use of this material,
  30. there shall be no use of the name of the Massachusetts Institute of
  31. Technology nor of any adaptation thereof in any advertising,
  32. promotional, or sales literature without prior written consent from
  33. MIT in each case. */
  34.  
  35. /* Unix system include file */
  36.  
  37. #ifndef SCM_UX_H
  38. #define SCM_UX_H
  39.  
  40. #define SYSTEM_NAME "unix"
  41.  
  42. #include <sys/types.h>
  43. #include <sys/times.h>
  44. #include <sys/file.h>
  45. #include <sys/stat.h>
  46. #include <sys/param.h>
  47. #include <stdio.h>
  48. #include <signal.h>
  49. #include <errno.h>
  50. #include <pwd.h>
  51. #include <grp.h>
  52. #include <utime.h>
  53.  
  54. #include "oscond.h"
  55. #include "ansidecl.h"
  56. #include "posixtype.h"
  57.  
  58. extern int errno;
  59.  
  60. /* These seem to be missing from versions of unistd.h */
  61. extern int EXFUN (ioctl, (int, int, ...));
  62. extern int EXFUN (open, (const char *, int, ...));
  63. extern int EXFUN (kill, (pid_t, int));
  64.  
  65. #include "intext.h"
  66. #include "dstack.h"
  67. #include "osscheme.h"
  68.  
  69. enum syscall_names
  70. {
  71.   syscall_accept,
  72.   syscall_bind,
  73.   syscall_chdir,
  74.   syscall_chmod,
  75.   syscall_close,
  76.   syscall_connect,
  77.   syscall_fcntl_GETFL,
  78.   syscall_fcntl_SETFL,
  79.   syscall_fork,
  80.   syscall_fstat,
  81.   syscall_ftruncate,
  82.   syscall_getcwd,
  83.   syscall_gethostname,
  84.   syscall_gettimeofday,
  85.   syscall_ioctl_TIOCGPGRP,
  86.   syscall_ioctl_TIOCSIGSEND,
  87.   syscall_kill,
  88.   syscall_link,
  89.   syscall_listen,
  90.   syscall_localtime,
  91.   syscall_lseek,
  92.   syscall_malloc,
  93.   syscall_mkdir,
  94.   syscall_open,
  95.   syscall_opendir,
  96.   syscall_pause,
  97.   syscall_pipe,
  98.   syscall_read,
  99.   syscall_readlink,
  100.   syscall_realloc,
  101.   syscall_rename,
  102.   syscall_select,
  103.   syscall_setitimer,
  104.   syscall_setpgid,
  105.   syscall_sighold,
  106.   syscall_sigprocmask,
  107.   syscall_sigsuspend,
  108.   syscall_sleep,
  109.   syscall_socket,
  110.   syscall_symlink,
  111.   syscall_tcdrain,
  112.   syscall_tcflush,
  113.   syscall_tcgetpgrp,
  114.   syscall_tcsetpgrp,
  115.   syscall_terminal_get_state,
  116.   syscall_terminal_set_state,
  117.   syscall_time,
  118.   syscall_times,
  119.   syscall_unlink,
  120.   syscall_utime,
  121.   syscall_vfork,
  122.   syscall_write,
  123.   syscall_stat,
  124.   syscall_lstat
  125. };
  126.  
  127. enum syserr_names
  128. {
  129.   syserr_unknown,
  130.   syserr_arg_list_too_long,
  131.   syserr_bad_address,
  132.   syserr_bad_file_descriptor,
  133.   syserr_broken_pipe,
  134.   syserr_directory_not_empty,
  135.   syserr_domain_error,
  136.   syserr_exec_format_error,
  137.   syserr_file_exists,
  138.   syserr_file_too_large,
  139.   syserr_filename_too_long,
  140.   syserr_function_not_implemented,
  141.   syserr_improper_link,
  142.   syserr_inappropriate_io_control_operation,
  143.   syserr_interrupted_function_call,
  144.   syserr_invalid_argument,
  145.   syserr_invalid_seek,
  146.   syserr_io_error,
  147.   syserr_is_a_directory,
  148.   syserr_no_child_processes,
  149.   syserr_no_locks_available,
  150.   syserr_no_space_left_on_device,
  151.   syserr_no_such_device,
  152.   syserr_no_such_device_or_address,
  153.   syserr_no_such_file_or_directory,
  154.   syserr_no_such_process,
  155.   syserr_not_a_directory,
  156.   syserr_not_enough_space,
  157.   syserr_operation_not_permitted,
  158.   syserr_permission_denied,
  159.   syserr_read_only_file_system,
  160.   syserr_resource_busy,
  161.   syserr_resource_deadlock_avoided,
  162.   syserr_resource_temporarily_unavailable,
  163.   syserr_result_too_large,
  164.   syserr_too_many_links,
  165.   syserr_too_many_open_files,
  166.   syserr_too_many_open_files_in_system
  167. };
  168.  
  169. extern void EXFUN (error_system_call, (int code, enum syscall_names name));
  170.  
  171. /* Conditionalizations that are overridden by _POSIX. */
  172.  
  173. #ifdef _POSIX
  174.  
  175. #ifdef sonyrisc
  176. /* <limits.h> will redefine these. */
  177. #undef DBL_MAX
  178. #undef DBL_MIN
  179. #undef FLT_MAX
  180. #undef FLT_MIN
  181. #endif
  182.  
  183. #include <limits.h>
  184. #include <unistd.h>
  185. #include <time.h>
  186. #include <termios.h>
  187. #include <fcntl.h>
  188. #include <sys/wait.h>
  189. #include <dirent.h>
  190.  
  191. #define DECL_GETLOGIN
  192. #define HAVE_APPEND
  193. #define HAVE_DIRENT
  194. #define HAVE_DUP2
  195. #define HAVE_FCNTL
  196. #define HAVE_GETCWD
  197. #define HAVE_MKDIR
  198. #define HAVE_POSIX_SIGNALS
  199. #define HAVE_RENAME
  200. #define HAVE_RMDIR
  201. #define HAVE_TERMIOS
  202. #define HAVE_TIMES
  203. #define HAVE_WAITPID
  204. #define VOID_SIGNAL_HANDLERS
  205.  
  206. #define ERRNO_NONBLOCK EAGAIN
  207. #define FCNTL_NONBLOCK O_NONBLOCK
  208.  
  209. #else /* not _POSIX */
  210. #ifdef _BSD
  211.  
  212. #include <fcntl.h>
  213. #include <sys/dir.h>
  214. #include <sgtty.h>
  215. #include <sys/time.h>
  216. #include <sys/wait.h>
  217.  
  218. #define HAVE_APPEND
  219. #define HAVE_BSD_SIGNALS
  220. #define HAVE_BSD_TTY_DRIVER
  221. #define HAVE_DIR
  222. #define HAVE_DUP2
  223. #define HAVE_FCNTL
  224. #define HAVE_GETWD
  225. #define HAVE_MKDIR
  226. #define HAVE_RENAME
  227. #define HAVE_RMDIR
  228. #define HAVE_TIMES
  229. #define HAVE_WAIT3
  230. /* MORE/BSD has this -- do all 4.3 implementations? */
  231. /* #define HAVE_WAIT4 */
  232. #define UNION_WAIT_STATUS
  233.  
  234. #if defined(_ULTRIX) || defined(_SUNOS4) || defined(sun4) || defined(_NEXTOS)
  235. #define VOID_SIGNAL_HANDLERS
  236. #endif
  237.  
  238. #if defined(_SUNOS4) && defined(SIG_BLOCK)
  239. #define HAVE_POSIX_SIGNALS
  240. #endif
  241.  
  242. #define ERRNO_NONBLOCK EWOULDBLOCK
  243. #define FCNTL_NONBLOCK FNDELAY
  244.  
  245. #else /* not _BSD */
  246. #ifdef _SYSV
  247.  
  248. #include <time.h>
  249. #include <termio.h>
  250. #include <fcntl.h>
  251.  
  252. #define HAVE_APPEND
  253. #define HAVE_FCNTL
  254. #define HAVE_GETCWD
  255. #define HAVE_TERMIO
  256. #define HAVE_TIMES
  257.  
  258. #define AMBIGUOUS_NONBLOCK
  259. #define ERRNO_NONBLOCK EAGAIN
  260. #define FCNTL_NONBLOCK O_NDELAY
  261.  
  262. #ifdef _SYSV3
  263.  
  264. #include <dirent.h>
  265.  
  266. #define HAVE_DIRENT
  267. #define HAVE_DUP2
  268. #define HAVE_MKDIR
  269. #define HAVE_RMDIR
  270. #define HAVE_SYSV3_SIGNALS
  271. #define VOID_SIGNAL_HANDLERS
  272.  
  273. #else /* not _SYSV3 */
  274. #ifdef _HPUX
  275.  
  276. #include <sys/wait.h>
  277.  
  278. #define HAVE_BSD_SIGNALS
  279. #define HAVE_DUP2
  280. #define HAVE_MKDIR
  281. #define HAVE_RENAME
  282. #define HAVE_RMDIR
  283. #define HAVE_WAIT3
  284.  
  285. #if (_HPUX_VERSION < 65)
  286.  
  287. #include <ndir.h>
  288. #define HAVE_DIR
  289.  
  290. #else /* (_HPUX_VERSION >= 65) */
  291.  
  292. #include <dirent.h>
  293. #define HAVE_DIRENT
  294. #define HAVE_POSIX_SIGNALS
  295. #define HAVE_WAITPID
  296. #define VOID_SIGNAL_HANDLERS
  297.  
  298. #endif /* _HPUX_VERSION */
  299.  
  300. #endif /* _HPUX */
  301. #endif /* _SYSV3 */
  302. #else /* not _SYSV */
  303. #ifdef _PIXEL
  304.  
  305. #include <time.h>
  306. #include <sgtty.h>
  307.  
  308. #define HAVE_BSD_TTY_DRIVER
  309. #define HAVE_DUMB_OPEN
  310. #define HAVE_DUP2
  311. #define HAVE_TIMES
  312.  
  313. #endif /* _PIXEL */
  314. #endif /* _SYSV */
  315. #endif /* _BSD */
  316. #endif /* _POSIX */
  317.  
  318. /* Conditionalizations that are independent of _POSIX. */
  319.  
  320. #ifdef _BSD
  321.  
  322. #define HAVE_BSD_JOB_CONTROL
  323. #define HAVE_FIONREAD
  324. #define HAVE_GETTIMEOFDAY
  325. #define HAVE_ITIMER
  326. #define HAVE_PTYS
  327. #define FIRST_PTY_LETTER 'p'
  328. #define HAVE_SELECT
  329. #define HAVE_SIGCONTEXT
  330. #define HAVE_SOCKETS
  331. #define HAVE_SYMBOLIC_LINKS
  332. #define HAVE_TRUNCATE
  333. #define HAVE_UNIX_SOCKETS
  334. #define HAVE_VFORK
  335.  
  336. #ifdef _ULTRIX
  337. #define SYSTEM_VARIANT "Ultrix"
  338. #endif
  339.  
  340. #ifdef _NEXTOS
  341. #define SYSTEM_VARIANT "NeXT"
  342. #endif
  343.  
  344. #ifdef apollo
  345. #define SYSTEM_VARIANT "Domain"
  346. #undef S_IFIFO
  347. #endif
  348.  
  349. #ifdef _SUNOS
  350.  
  351. #define SYSTEM_VARIANT "SunOS"
  352.  
  353. #include <sys/vadvise.h>
  354. #ifdef _SUNOS3
  355. #define USE_HOSTENT_ADDR
  356. #endif
  357.  
  358. #else /* not _SUNOS */
  359.  
  360. #ifdef _BSD4_2
  361. #define USE_HOSTENT_ADDR
  362. #endif
  363.  
  364. #endif /* _SUNOS */
  365.  
  366. #ifndef SYSTEM_VARIANT
  367. #define SYSTEM_VARIANT "BSD"
  368. #endif
  369.  
  370. #else /* not _BSD */
  371. #ifdef _HPUX
  372.  
  373. #include <sys/ptyio.h>
  374.  
  375. #define SYSTEM_VARIANT "HP-UX"
  376. #define HAVE_GETTIMEOFDAY
  377. #define HAVE_ITIMER
  378. #define HAVE_NICE
  379. #define HAVE_PTYS
  380. #define FIRST_PTY_LETTER 'p'
  381. #define HAVE_SELECT
  382. #define HAVE_SIGCONTEXT
  383. #define HAVE_SOCKETS
  384. #define HAVE_SYMBOLIC_LINKS
  385. #define HAVE_TRUNCATE
  386. #define HAVE_VFORK
  387.  
  388. #if (_HPUX_VERSION >= 65)
  389. /* Is this right for 800-series machines? */
  390. #define HAVE_UNIX_SOCKETS
  391. #endif
  392.  
  393. #if (_HPUX_VERSION >= 65) || defined(hp9000s800)
  394. #include <bsdtty.h>
  395. #define HAVE_BSD_JOB_CONTROL
  396. #endif
  397.  
  398. #if (_HPUX_VERSION >= 70) || defined(hp9000s800)
  399. #define HAVE_FIONREAD
  400. #endif
  401.  
  402. #if (_HPUX_VERSION <= 65)
  403. #define USE_HOSTENT_ADDR
  404. #endif
  405.  
  406. #else /* not _HPUX */
  407. #ifdef _AIX
  408.  
  409. #define SYSTEM_VARIANT "AIX"
  410. #define HAVE_SOCKETS
  411. #define HAVE_VFORK
  412.  
  413. #else /* not _AIX */
  414. #ifdef _SYSV4
  415.  
  416. #define SYSTEM_VARIANT "ATT (Vr4)"
  417.  
  418. #define HAVE_FIONREAD
  419. #define HAVE_GETTIMEOFDAY
  420. #define HAVE_ITIMER
  421. #define HAVE_NICE
  422. #define HAVE_PTYS
  423. #define HAVE_SELECT
  424. #define HAVE_SIGCONTEXT
  425. #define HAVE_SOCKETS
  426. #define HAVE_SYMBOLIC_LINKS
  427. #define HAVE_TRUNCATE
  428. #define HAVE_UNIX_SOCKETS
  429. #define HAVE_VFORK
  430.  
  431. #include <stropts.h>
  432.  
  433. #define PTY_DECLARATIONS                        \
  434.   extern int EXFUN (grantpt, (int));                    \
  435.   extern int EXFUN (unlockpt, (int));                    \
  436.   extern char * EXFUN (ptsname, (int))
  437.  
  438. #undef PTY_ITERATION
  439.  
  440. #define PTY_MASTER_NAME_SPRINTF(master_name)                \
  441.   sprintf ((master_name), "/dev/ptmx")
  442.  
  443. #define PTY_SLAVE_NAME_SPRINTF(slave_name, fd)                \
  444. {                                    \
  445.   grantpt (fd);                                \
  446.   unlockpt (fd);                            \
  447.   sprintf ((slave_name), "%s", (ptsname (fd)));                \
  448. }
  449.  
  450. /* Would be nice if HPUX and SYSV4 agreed on the name of this. */
  451. #define TIOCSIGSEND TIOCSIGNAL
  452.  
  453. /* Must push various STREAMS modules onto the slave side of a PTY when
  454.    it is opened. */
  455.  
  456. #define SLAVE_PTY_P(filename) ((strncmp ((filename), "/dev/pts/", 9)) == 0)
  457.  
  458. #define SETUP_SLAVE_PTY(fd)                        \
  459.   (((ioctl ((fd), I_PUSH, "ptem")) >= 0)                \
  460.    && ((ioctl ((fd), I_PUSH, "ldterm")) >= 0)                \
  461.    && ((ioctl ((fd), I_PUSH, "ttcompat")) >= 0))
  462.  
  463. #else /* not _SYSV4 */
  464. #ifdef _SYSV3
  465.  
  466. #define SYSTEM_VARIANT "ATT (Vr3)"
  467.  
  468. #else /* not _SYSV3 */
  469. #ifdef _SYSV
  470.  
  471. #define SYSTEM_VARIANT "ATT (V)"
  472.  
  473. #else /* not _SYSV */
  474. #ifdef _PIXEL
  475.  
  476. #define SYSTEM_VARIANT "Pixel"
  477.  
  478. #define HAVE_FIONREAD
  479. #define HAVE_NICE
  480.  
  481. #else /* not _PIXEL */
  482.  
  483. #define SYSTEM_VARIANT "unknown"
  484.  
  485. #endif /* not _PIXEL */
  486. #endif /* not _SYSV */
  487. #endif /* not _SYSV3 */
  488. #endif /* not _SYSV4 */
  489. #endif /* not _AIX */
  490. #endif /* not _HPUX */
  491. #endif /* not _BSD */
  492.  
  493. #ifdef VOID_SIGNAL_HANDLERS
  494. typedef void Tsignal_handler_result;
  495. #define SIGNAL_HANDLER_RETURN() return
  496. #else
  497. typedef int Tsignal_handler_result;
  498. #define SIGNAL_HANDLER_RETURN() return (0)
  499. #endif
  500.  
  501. typedef Tsignal_handler_result (*Tsignal_handler) ();
  502.  
  503. #ifndef SIG_ERR
  504. #define SIG_ERR ((Tsignal_handler) (-1))
  505. #endif
  506.  
  507. #if !defined(SIGCHLD) && defined(SIGCLD)
  508. #define SIGCHLD SIGCLD
  509. #endif
  510. #if !defined(SIGABRT) && defined(SIGIOT)
  511. #define SIGABRT SIGIOT
  512. #endif
  513.  
  514. #ifndef HAVE_SIGCONTEXT
  515. struct sigcontext { long sc_sp, sc_pc; };
  516. #define HAVE_SIGCONTEXT
  517. #endif
  518.  
  519. /* Crufty, but it will work here. */
  520. #ifndef ENOSYS
  521. #define ENOSYS 0
  522. #endif
  523.  
  524. #ifdef UNION_WAIT_STATUS
  525.  
  526. typedef union wait wait_status_t;
  527.  
  528. #ifndef WEXITSTATUS
  529. #define WEXITSTATUS(_X) ((_X) . w_retcode)
  530. #endif
  531.  
  532. #ifndef WTERMSIG
  533. #define WTERMSIG(_X) ((_X) . w_termsig)
  534. #endif
  535.  
  536. #ifndef WSTOPSIG
  537. #define WSTOPSIG(_X) ((_X) . w_stopsig)
  538. #endif
  539.  
  540. #else /* not UNION_WAIT_STATUS */
  541.  
  542. typedef int wait_status_t;
  543.  
  544. #ifndef WIFEXITED
  545. #define WIFEXITED(_X) (((_X) & 0377) == 0)
  546. #endif
  547.  
  548. #ifndef WIFSTOPPED
  549. #define WIFSTOPPED(_X) (((_X) & 0377) == 0177)
  550. #endif
  551.  
  552. #ifndef WIFSIGNALED
  553. #define WIFSIGNALED(_X) ((((_X) & 0377) != 0) && (((_X) & 0377) != 0177))
  554. #endif
  555.  
  556. #ifndef WEXITSTATUS
  557. #define WEXITSTATUS(_X) (((_X) >> 8) & 0377)
  558. #endif
  559.  
  560. #ifndef WTERMSIG
  561. #define WTERMSIG(_X) ((_X) & 0177)
  562. #endif
  563.  
  564. #ifndef WSTOPSIG
  565. #define WSTOPSIG(_X) (((_X) >> 8) & 0377)
  566. #endif
  567.  
  568. #endif /* UNION_WAIT_STATUS */
  569.  
  570. /* Provide null defaults for all the signals we're likely to use so we
  571.    aren't continually testing to see if they're defined. */
  572.  
  573. #ifndef SIGLOST
  574. #define SIGLOST 0
  575. #endif
  576. #ifndef SIGWINCH
  577. #define SIGWINCH 0
  578. #endif
  579. #ifndef SIGURG
  580. #define SIGURG 0
  581. #endif
  582. #ifndef SIGIO
  583. #define SIGIO 0
  584. #endif
  585. #ifndef SIGUSR1
  586. #define SIGUSR1 0
  587. #endif
  588. #ifndef SIGUSR2
  589. #define SIGUSR2 0
  590. #endif
  591. #ifndef SIGVTALRM
  592. #define SIGVTALRM 0
  593. #endif
  594. #ifndef SIGABRT
  595. #define SIGABRT 0
  596. #endif
  597. #ifndef SIGPWR
  598. #define SIGPWR 0
  599. #endif
  600. #ifndef SIGPROF
  601. #define SIGPROF 0
  602. #endif
  603. #ifndef SIGSTOP
  604. #define SIGSTOP 0
  605. #endif
  606. #ifndef SIGTSTP
  607. #define SIGTSTP 0
  608. #endif
  609. #ifndef SIGCONT
  610. #define SIGCONT 0
  611. #endif
  612. #ifndef SIGCHLD
  613. #define SIGCHLD 0
  614. #endif
  615. #ifndef SIGTTIN
  616. #define SIGTTIN 0
  617. #endif
  618. #ifndef SIGTTOU
  619. #define SIGTTOU 0
  620. #endif
  621.  
  622. /* constants for access() */
  623. #ifndef R_OK
  624. #define R_OK 4
  625. #define W_OK 2
  626. #define X_OK 1
  627. #define F_OK 0
  628. #endif
  629.  
  630. #ifndef MAXPATHLEN
  631. #define MAXPATHLEN 1024
  632. #endif
  633.  
  634. #ifdef __STDC__
  635. #define ALERT_CHAR '\a'
  636. #define ALERT_STRING "\a"
  637. #else
  638. #define ALERT_CHAR '\007'
  639. #define ALERT_STRING "\007"
  640. #endif
  641.  
  642. #ifndef STDIN_FILENO
  643. #define STDIN_FILENO 0
  644. #define STDOUT_FILENO 1
  645. #define STDERR_FILENO 2
  646. #endif
  647.  
  648. /* constants for open() and fcntl() */
  649. #ifndef O_RDONLY
  650. #define O_RDONLY 0
  651. #define O_WRONLY 1
  652. #define O_RDWR 2
  653. #endif
  654.  
  655. /* mode bit definitions for open(), creat(), and chmod() */
  656. #ifndef S_IRWXU
  657. #define S_IRWXU 0700
  658. #define S_IRWXG 0070
  659. #define S_IRWXO 0007
  660. #endif
  661.  
  662. #ifndef S_IRUSR
  663. #define S_IRUSR 0400
  664. #define S_IWUSR 0200
  665. #define S_IXUSR 0100
  666. #define S_IRGRP 0040
  667. #define S_IWGRP 0020
  668. #define S_IXGRP 0010
  669. #define S_IROTH 0004
  670. #define S_IWOTH 0002
  671. #define S_IXOTH 0001
  672. #endif
  673.  
  674. #define MODE_REG (S_IRUSR | S_IWUSR | S_IRGRP | S_IWGRP | S_IROTH | S_IWOTH)
  675. #define MODE_DIR (MODE_REG | S_IXUSR | S_IXGRP | S_IXOTH)
  676.  
  677. /* constants for lseek() */
  678. #ifndef SEEK_SET
  679. #define SEEK_SET 0
  680. #define SEEK_CUR 1
  681. #define SEEK_END 2
  682. #endif
  683.  
  684. #ifndef DECL_GETLOGIN
  685. extern char * EXFUN (getlogin, (void));
  686. #endif
  687.  
  688. #define UX_abort abort
  689. #define UX_access access
  690. #define UX_alarm alarm
  691. #define UX_chdir chdir
  692. #define UX_chmod chmod
  693. #define UX_close close
  694. #define UX_ctime ctime
  695. #define UX_dup dup
  696. #define UX_free free
  697. #define UX_fstat fstat
  698. #define UX_getenv getenv
  699. #define UX_getegid getegid
  700. #define UX_geteuid geteuid
  701. #define UX_getgrgid getgrgid
  702. #define UX_gethostname gethostname
  703. #define UX_getlogin getlogin
  704. #define UX_getpid getpid
  705. #define UX_getpwnam getpwnam
  706. #define UX_getpwuid getpwuid
  707. #define UX_ioctl ioctl
  708. #define UX_link link
  709. #define UX_localtime localtime
  710. #define UX_lseek lseek
  711. #define UX_malloc malloc
  712. #define UX_mknod mknod
  713. #define UX_pause pause
  714. #define UX_pipe pipe
  715. #define UX_read read
  716. #define UX_realloc realloc
  717. #define UX_signal signal
  718. #define UX_sleep sleep
  719. #define UX_stat stat
  720. #define UX_system system
  721. #define UX_time time
  722. #define UX_unlink unlink
  723. #define UX_utime utime
  724. #define UX_write write
  725. #define UX_wait wait
  726.  
  727. extern PTR EXFUN (malloc, (unsigned int size));
  728. extern PTR EXFUN (realloc, (PTR ptr, unsigned int size));
  729. extern CONST char * EXFUN (getenv, (CONST char * name));
  730. extern int EXFUN (gethostname, (char * name, unsigned int size));
  731.  
  732. #ifdef HAVE_FCNTL
  733. #define UX_fcntl fcntl
  734. #endif
  735.  
  736. #ifdef HAVE_TRUNCATE
  737. #define UX_ftruncate ftruncate
  738. #define UX_truncate truncate
  739. #endif
  740.  
  741. #ifdef HAVE_VFORK
  742. #define UX_vfork vfork
  743. #else
  744. #define UX_vfork fork
  745. #endif
  746.  
  747. #ifdef HAVE_SYMBOLIC_LINKS
  748. #define UX_lstat lstat
  749. #define UX_readlink readlink
  750. #define UX_symlink symlink
  751. #else
  752. #define UX_lstat stat
  753. #endif
  754.  
  755. extern void EXFUN (UX_prim_check_errno, (enum syscall_names name));
  756.  
  757. #define STD_VOID_SYSTEM_CALL(name, expression)                \
  758. {                                    \
  759.   while ((expression) < 0)                        \
  760.     if (errno != EINTR)                            \
  761.       error_system_call (errno, (name));                \
  762. }
  763.  
  764. #define STD_UINT_SYSTEM_CALL(name, result, expression)            \
  765. {                                    \
  766.   while (((result) = (expression)) < 0)                    \
  767.     if (errno != EINTR)                            \
  768.       error_system_call (errno, (name));                \
  769. }
  770.  
  771. #define STD_PTR_SYSTEM_CALL(name, result, expression)            \
  772. {                                    \
  773.   while (((result) = (expression)) == 0)                \
  774.     if (errno != EINTR)                            \
  775.       error_system_call (errno, (name));                \
  776. }
  777.  
  778. #ifdef HAVE_TERMIOS
  779.  
  780. typedef struct
  781. {
  782.   struct termios tio;
  783. #ifdef _HPUX
  784.   struct ltchars ltc;
  785. #endif
  786. } Ttty_state;
  787.  
  788. #define UX_tcflush tcflush
  789. #define UX_tcdrain tcdrain
  790. #define UX_tcgetattr tcgetattr
  791. #define UX_tcsetattr tcsetattr
  792.  
  793. #else /* not HAVE_TERMIOS */
  794.  
  795. extern int EXFUN (UX_tcdrain, (int fd));
  796. extern int EXFUN (UX_tcflush, (int fd, int queue_selector));
  797. /* These values chosen to match the ioctl TCFLSH argument for termio. */
  798. #define TCIFLUSH 0
  799. #define TCOFLUSH 1
  800. #define TCIOFLUSH 2
  801.  
  802. #ifdef HAVE_TERMIO
  803.  
  804. typedef struct
  805. {
  806.   struct termio tio;
  807. #ifdef HAVE_BSD_JOB_CONTROL
  808.   struct ltchars ltc;
  809. #endif
  810. } Ttty_state;
  811.  
  812. #else /* not HAVE_TERMIO */
  813. #ifdef HAVE_BSD_TTY_DRIVER
  814.  
  815. typedef struct
  816. {
  817.   struct sgttyb sg;
  818.   struct tchars tc;
  819. #ifdef HAVE_BSD_JOB_CONTROL
  820.   struct ltchars ltc;
  821. #endif
  822.   int lmode;
  823. } Ttty_state;
  824.  
  825. #endif /* HAVE_BSD_TTY_DRIVER */
  826. #endif /* HAVE_TERMIO */
  827. #endif /* HAVE_TERMIOS */
  828.  
  829. extern int EXFUN (UX_terminal_get_state, (int fd, Ttty_state * s));
  830. extern int EXFUN (UX_terminal_set_state, (int fd, Ttty_state * s));
  831.  
  832. #ifdef _POSIX
  833. #define UX_getpgrp getpgrp
  834. #define UX_setsid setsid
  835. #else
  836. #ifdef _SYSV
  837. #define UX_getpgrp getpgrp
  838. #define UX_setsid setpgrp
  839. #else /* not _SYSV */
  840. extern pid_t EXFUN (UX_getpgrp, (void));
  841. extern pid_t EXFUN (UX_setsid, (void));
  842. #endif /* _SYSV */
  843. #endif /* _POSIX */
  844.  
  845. #ifdef _POSIX
  846.  
  847. #define UX_setpgid setpgid
  848. #define UX_tcgetpgrp tcgetpgrp
  849. #define UX_tcsetpgrp tcsetpgrp
  850.  
  851. #else /* not _POSIX */
  852.  
  853. extern pid_t EXFUN (UX_tcgetpgrp, (int fd));
  854. extern int EXFUN (UX_tcsetpgrp, (int fd, pid_t pgrp_id));
  855.  
  856. #ifdef HAVE_BSD_JOB_CONTROL
  857.  
  858. #ifdef _SYSV
  859. #define UX_setpgid setpgrp2
  860. #else
  861. #define UX_setpgid setpgrp
  862. #endif
  863.  
  864. #endif /* HAVE_BSD_JOB_CONTROL */
  865. #endif /* _POSIX */
  866.  
  867. #ifdef HAVE_GETTIMEOFDAY
  868. #define UX_gettimeofday gettimeofday
  869. #endif
  870. #ifdef HAVE_ITIMER
  871. #define UX_setitimer setitimer
  872. #endif
  873. #ifdef HAVE_RMDIR
  874. #define UX_rmdir rmdir
  875. #endif
  876. #ifdef HAVE_TIMES
  877. #define UX_times times
  878. #endif
  879. #ifdef HAVE_SOCKETS
  880. #define UX_connect connect
  881. #define UX_gethostbyname gethostbyname
  882. #define UX_getservbyname getservbyname
  883. #define UX_socket socket
  884. #define UX_bind bind
  885. #define UX_listen listen
  886. #define UX_accept accept
  887. #endif
  888.  
  889. #ifdef HAVE_DUMB_OPEN
  890. extern int EXFUN (UX_open, (CONST char * name, int oflag, mode_t mode));
  891. #else
  892. #define UX_open open
  893. #endif
  894.  
  895. #ifdef HAVE_DUP2
  896. #define UX_dup2 dup2
  897. #else
  898. #ifdef HAVE_FCNTL
  899. #define EMULATE_DUP2
  900. #define HAVE_DUP2
  901. extern int EXFUN (UX_dup2, (int fd, int fd2));
  902. #endif
  903. #endif
  904.  
  905. #ifdef HAVE_GETCWD
  906. #define UX_getcwd getcwd
  907. #else
  908. #define EMULATE_GETCWD
  909. #define HAVE_GETCWD
  910. extern char * EXFUN (UX_getcwd, (char * buffer, size_t length));
  911. #endif
  912.  
  913. #ifdef HAVE_MKDIR
  914. #define UX_mkdir mkdir
  915. #else
  916. #define EMULATE_MKDIR
  917. #define HAVE_MKDIR
  918. extern int EXFUN (UX_mkdir, (CONST char * name, mode_t mode));
  919. #endif
  920.  
  921. #ifdef HAVE_RENAME
  922. #define UX_rename rename
  923. #else
  924. #define EMULATE_RENAME
  925. #define HAVE_RENAME
  926. extern int EXFUN (UX_rename, (CONST char * from_name, CONST char * to_name));
  927. #endif
  928.  
  929. #ifdef HAVE_WAITPID
  930. #define UX_waitpid waitpid
  931. #else /* not HAVE_WAITPID */
  932. #ifdef HAVE_WAIT3
  933. #define EMULATE_WAITPID
  934. #define HAVE_WAITPID
  935. extern int EXFUN
  936.   (UX_waitpid, (pid_t pid, wait_status_t * stat_loc, int options));
  937. #endif /* HAVE_WAIT3 */
  938. #endif /* HAVE_WAITPID */
  939.  
  940. #ifndef WUNTRACED
  941. #define WUNTRACED 0
  942. #endif
  943.  
  944. #ifdef HAVE_SELECT
  945. #define UX_select select
  946. #endif /* HAVE_SELECT */
  947.  
  948. #ifdef _BSD
  949. #define BSD_DEV_TTY "/dev/tty"
  950. #endif
  951.  
  952. #if !defined(_POSIX) && defined(_BSD) && !defined(_SUNOS) && !defined(_ULTRIX)
  953. #define L_ctermid ((strlen (BSD_DEV_TTY)) + 1);
  954. extern char * EXFUN (UX_ctermid, (char * s));
  955. #else
  956. #define UX_ctermid ctermid
  957. #endif
  958.  
  959. #if !defined(_POSIX) && defined(_BSD) && !defined(_SUNOS)
  960. extern int EXFUN (UX_kill, (pid_t pid, int sig));
  961. #else
  962. #define UX_kill kill
  963. #endif
  964.  
  965. #ifdef HAVE_POSIX_SIGNALS
  966.  
  967. #define UX_sigemptyset sigemptyset
  968. #define UX_sigfillset sigfillset
  969. #define UX_sigaddset sigaddset
  970. #define UX_sigdelset sigdelset
  971. #define UX_sigismember sigismember
  972. #define UX_sigaction sigaction
  973. #define UX_sigsuspend sigsuspend
  974. #define UX_sigprocmask sigprocmask
  975.  
  976. #else /* not HAVE_POSIX_SIGNALS */
  977.  
  978. typedef long sigset_t;
  979. extern int EXFUN (UX_sigemptyset, (sigset_t * set));
  980. extern int EXFUN (UX_sigfillset, (sigset_t * set));
  981. extern int EXFUN (UX_sigaddset, (sigset_t * set, int signo));
  982. extern int EXFUN (UX_sigdelset, (sigset_t * set, int signo));
  983. extern int EXFUN (UX_sigismember, (CONST sigset_t * set, int signo));
  984.  
  985. #ifdef HAVE_BSD_SIGNALS
  986.  
  987. struct sigaction
  988. {
  989.   Tsignal_handler sa_handler;
  990.   sigset_t sa_mask;
  991.   int sa_flags;
  992. };
  993.  
  994. extern int EXFUN
  995.   (UX_sigaction,
  996.    (int signo, CONST struct sigaction * act, struct sigaction * oact));
  997. extern int EXFUN
  998.   (UX_sigprocmask, (int how, CONST sigset_t * set, sigset_t * oset));
  999. extern int EXFUN (UX_sigsuspend, (CONST sigset_t * set));
  1000. #define SIG_BLOCK 0
  1001. #define SIG_UNBLOCK 1
  1002. #define SIG_SETMASK 2
  1003.  
  1004. #define HAVE_POSIX_SIGNALS
  1005.  
  1006. #else /* not HAVE_BSD_SIGNALS */
  1007. #ifdef HAVE_SYSV3_SIGNALS
  1008.  
  1009. #define UX_sigset sigset
  1010. #define UX_sighold sighold
  1011. #define UX_sigrelse sigrelse
  1012.  
  1013. #endif /* HAVE_SYSV3_SIGNALS */
  1014. #endif /* HAVE_BSD_SIGNALS */
  1015. #endif /* HAVE_POSIX_SIGNALS */
  1016.  
  1017. #ifdef _POSIX
  1018.  
  1019. extern cc_t EXFUN (UX_PC_VDISABLE, (int fildes));
  1020. extern clock_t EXFUN (UX_SC_CLK_TCK, (void));
  1021. #define UX_SC_OPEN_MAX() ((size_t) (sysconf (_SC_OPEN_MAX)))
  1022. #define UX_SC_CHILD_MAX() ((size_t) (sysconf (_SC_CHILD_MAX)))
  1023.  
  1024. #ifdef _POSIX_JOB_CONTROL
  1025. #define UX_SC_JOB_CONTROL() 1
  1026. #else
  1027. #define UX_SC_JOB_CONTROL() ((sysconf (_SC_JOB_CONTROL)) >= 0)
  1028. #endif
  1029.  
  1030. #else /* not _POSIX */
  1031.  
  1032. #define UX_PC_VDISABLE(fildes) '\377'
  1033.  
  1034. #ifdef OPEN_MAX
  1035. #define UX_SC_OPEN_MAX() OPEN_MAX
  1036. #else
  1037. #ifdef _NFILE
  1038. #define UX_SC_OPEN_MAX() _NFILE
  1039. #else
  1040. #define UX_SC_OPEN_MAX() 16
  1041. #endif
  1042. #endif
  1043.  
  1044. #ifdef CHILD_MAX
  1045. #define UX_SC_CHILD_MAX() CHILD_MAX
  1046. #else
  1047. #define UX_SC_CHILD_MAX() 6
  1048. #endif
  1049.  
  1050. #ifdef CLK_TCK
  1051. #define UX_SC_CLK_TCK() CLK_TCK
  1052. #else
  1053. #ifdef HZ
  1054. #define UX_SC_CLK_TCK() HZ
  1055. #else
  1056. #define UX_SC_CLK_TCK() 60
  1057. #endif
  1058. #endif
  1059.  
  1060. #ifdef HAVE_BSD_JOB_CONTROL
  1061. #define UX_SC_JOB_CONTROL() 1
  1062. #else
  1063. #define UX_SC_JOB_CONTROL() 0
  1064. #endif
  1065.  
  1066. #endif /* _POSIX */
  1067.  
  1068. #endif /* SCM_UX_H */
  1069.